package com.shujunjun.project.strategy.junjun;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author wsh
 * @since 2024/3/17 9:50
 */
@Slf4j
@Component
public class JunJunFactory {
    private final Map<String, IJunJunService> map = new ConcurrentHashMap<>();

    /**
     * 注册bean
     *
     * @param name          bean标识
     * @param junJunService 具体实现
     */
    public void register(String name, IJunJunService junJunService) {
        if (StringUtils.isEmpty(name) || null == junJunService) {
            return;
        }
        map.put(name, junJunService);
    }

    /**
     * 根据名称获取具体实现
     *
     * @param name 名称
     * @return 具体实现
     */
    public IJunJunService getInvokeStrategy(String name) {
        if (StringUtils.isEmpty(name)) {
            return null;
        }
        return map.get(name);
    }
}
